<script setup>
import Edit from './components/Edit.vue'

import axios from 'axios'
import { ref } from 'vue'

let list = ref([])

let getList = () => {
  axios.get('/list').then(res => {
    list.value = res.data
  }).catch(err => {
    console.log(err)
  })
}
getList()

let delate = (data) => {
  axios.delete(`/del/${data.id}`).then(res => {
    getList()
    alert('删除成功！')
  }).catch(err => {
    console.log(err)
  })
}



let set = ref(null)
let showSet = (data) => {
  set.value.changeDV(data)
}


let changeF = () => {
  getList()
}
</script>

<template>
  <div class="app">
    <el-table :data="list">
      <el-table-column label="ID" prop="id"></el-table-column>
      <el-table-column label="姓名" prop="name" width="150"></el-table-column>
      <el-table-column label="籍贯" prop="place"></el-table-column>
      <el-table-column label="操作" width="150">
        <template v-slot="scope">
          <el-button type="primary" @click='showSet(scope.row)' link>编辑</el-button>
          <el-button type="danger" @click="delate(scope.row)" link>删除</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
  <Edit @changeF="changeF" ref="set" />
</template>

<style scoped>
.app {
  width: 980px;
  margin: 100px auto 0;
}
</style>
